// pages/Settlement/OrderRecord/OrderRecord.js
const controllers = require('../../controllers/controllerIndex.js').controller;
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    status:-1,
    orderList:[ ],
    isPickerRender: false,
    isPickerShow: false,
    startTime: "",
    endTime: " ",
    keywork:"",
    pickerConfig: {
      endDate: true,
      column: "",
      dateLimit: true,
      initStartTime: "2019-01-01 12:32:44",
      initEndTime: " ",
      limitStartTime: "2015-05-06 12:32:44",
      limitEndTime: "2055-05-06 12:32:44"
    },
    tabs: [
      {
        name: "全部",
        type: 0,
        isActive: true
      },
      {
        name: "待结算",
        type: 1,
        isActive: false
      },
      {
        name: "已完成",
        type: 2,
        isActive: false
      },

      {
        name: "已取消",
        type: 3,
        isActive: false
      }
    ]
  },
  change:function(res){
 this.setData({
  keywork:res.detail.dataset
 })
  },
 
  checkOrder :function(){
    var that =this
    let params={
      sessionId: wx.getStorageSync('token'),
      shopId:wx.getStorageSync('shopId'),
     
        startTime:  that.data.startTime,
        endTime : that.data.endTime,
        keywork:that.data.keywork,
        pageNumber:1,
        pageSize :200,//目前没有发现分页，数量放大一点，后期需要加分页
        
       
    }
    if(that.data.status != -1){
      params.state=that.data.status
    }
    controllers.selectOrder(
      params
    ).then(res =>{
      that.setData({
        orderList: res.data.list
      })
    })
  },
  bindPickerChange: function(e) {
    console.log("picker发送选择改变，携带值为", e.detail.value);
    console.log(this.data.sensorList);

    this.getData(this.data.sensorList[e.detail.value].id);
    // let startDate = util.formatTime(new Date(new Date().getTime() - 24 * 60 * 60 * 1000 * 7));
    // let endDate = util.formatTime(new Date());
    this.setData({
      index: e.detail.value,
      sensorId: this.data.sensorList[e.detail.value].id
      // startDate,
      // endDate
    });
  },
  setPickerTime: function(val) {
    console.log(val);
    let data = val.detail;
    let startTime=/\d{4}-\d{1,2}-\d{1,2}/g.exec(data.startTime)
    let endTime=/\d{4}-\d{1,2}-\d{1,2}/g.exec(data.endTime)
    this.setData({
      startTime: startTime,
      endTime:endTime
    });
  }, pickerShow: function() {
    this.setData({
      isPickerShow: true,
      isPickerRender: true,
      chartHide: true
    });
  },
  pickerHide: function() {
    this.setData({
      isPickerShow: false,
      chartHide: false
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   let newTime=new Date();
   let dateTime=new Date();
    dateTime=dateTime.setDate(newTime.getDate()+1);
   dateTime=new Date(dateTime);
  
  
   this.setData({
    endTime: dateTime.getFullYear()+'-'+  (dateTime.getMonth()+1)+'-'+ dateTime.getDate(),
    startTime: newTime.getFullYear()+'-'+  (newTime.getMonth()+1)+'-'+ newTime.getDate(),
    'pickerConfig.initEndTime':newTime.getFullYear()+'-'+  (newTime.getMonth()+1)+'-'+ newTime.getDate(),
    'pickerConfig.initStartTime':newTime.getFullYear()+'-'+  (newTime.getMonth()+1)+'-'+ newTime.getDate()
   })
   this.checkOrder()
  },
  clikcTabs(e) {
    const { index } = e.detail
    let {tabs} = this.data
    tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false);
    this.setData({
      tabs,
      status:index-1
    })
    this.checkOrder()
  },
  orderDetails(res) {
     
    wx.navigateTo({
      url: '../OrderDetails/OrderDetails?id='+res.currentTarget.dataset.id,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.checkOrder()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
   // onShareAppMessage: function () {

  // }
})